//
//  HWWEDITABLETEXTViewController.m
//  HwwEditableText
//
//  Created by huangwenwu on 02/16/2020.
//  Copyright (c) 2020 huangwenwu. All rights reserved.
//

#import "HWWEDITABLETEXTViewController.h"
#import <HwwEditableTextFramework/HwwEditableTextFramework.h>
#define kShowMessage(msg) \
[[[UIAlertView alloc] initWithTitle:@"文本点击" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil] show];

@interface HWWEDITABLETEXTViewController ()
@property (nonatomic,  strong) HwwTapTextView *textView1;

@end

@implementation HWWEDITABLETEXTViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.textView1];

    _textView1.frame = CGRectMake(10, 100, CGRectGetWidth(self.view.frame)-20, 10);
    _textView1.autoWidth = YES;
    _textView1.autoHeight = YES; // Default is 'YES'
    _textView1.text = @"双十一，剁手季！查看详情~,请你遵守《注册协议》,并阅读《隐私政策》";
    _textView1.okidoki
    .attributedSubstring(@"《注册协议》",[UIColor redColor]).attributedSubstring(@"《隐私政策》",[UIColor greenColor]);
    
    [_textView1 addTapTexts:@[@"《注册协议》",@"《隐私政策》"] callback:^(NSString *text, NSRange range) {
        NSString *msg = [NSString stringWithFormat:@"text:%@,range:%@",text,NSStringFromRange(range)];
        kShowMessage(msg)
        NSLog(@"%@",msg);
    }];
}


- (HwwTapTextView *)setupTapTextView
{
    HwwTapTextView *textView = [[HwwTapTextView alloc] init];
    textView.textColor = [UIColor blackColor];
    textView.backgroundColor = [UIColor grayColor];
    textView.font = [UIFont systemFontOfSize:14];
    textView.textAlignment = NSTextAlignmentLeft;
    textView.highlightedBackgroundColor = [UIColor clearColor];
    return textView;
}

#pragma mark -------------------------------------事件-------------------------------------------

#pragma mark --- HwwTapTextViewDelegate
//
//- (void)tapTextView:(HwwTapTextView *)tapTextView didClickText:(NSString *)text range:(NSRange)range
//{
//    NSString *msg = [NSString stringWithFormat:@"text:%@,range:%@",text,NSStringFromRange(range)];
//    kShowMessage(msg)
//    NSLog(@"%@",msg);
//}

#pragma mark -------------------------------------懒加载-----------------------------------------

- (HwwTapTextView *)textView1{
    if (!_textView1) {
        _textView1 = [self setupTapTextView];
    }
    return _textView1;
}
@end
